<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>   
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>
    <meta name="keywords" content="用户管理">
    <meta name="description" content="用户管理">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.css" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/layer/skin/default/layer.css" rel="stylesheet">
    <link href="/Public/Admin/js/plugins/layer/laypage/skin/laypage.css" rel="stylesheet">
    <style>
    /*.b-page {background: #fff;box-shadow: 0px 1px 2px 0px #E2E2E2;}
    .page {width: 100%;padding: 30px 15px;background: #FFF;text-align: center;overflow: hidden;}
    .page .first,.page .prev,.page .current,.page .num,.page .current,.page .next,.page .end {padding: 8px 16px;margin: 0px 5px;display: inline-block;color: #008CBA;border: 1px solid #F2F2F2;
  border-radius: 5px;}
    .page .first:hover,.page .prev:hover,.page .current:hover,.page .num:hover,.page .current:hover,.page .next:hover,.page .end:hover {text-decoration: none;background: #F8F5F5;}
    .page .current {background-color: #008CBA;color: #FFF;border-radius: 5px;border: 1px solid #008CBA;}
    .page .current:hover {text-decoration: none;background: #008CBA;}
    .page .not-allowed {cursor: not-allowed;}*/
    #show img{width:60px; height: 60px; border-radius: 50%; box-shadow: 0 0 5px 1px #999;}
    #show td{text-align: center;}
    th{text-align: center;}
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>管理员列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-4">
                            <div class="input-group">
                                <a href="<?php echo U('User/add');?>" class="btn btn-outline btn-primary ">添加管理员</a>
                            </div>
                        </div>
                        <form name="admin_list" id="admin_list" action="<?php echo U('index');?>" method="get">
                            <div class="col-sm-5">
                                <div class="input-group">
                                    <input type="text" placeholder="请输入关键词" class="input-sm form-control" name="title" id="title" value="<?php echo ($title); ?>"> <span class="input-group-btn">
                                    <button type="submit" id="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="hr-line-dashed" style="margin: 10px"></div>
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>管理员账号</th>
                                <th>头像</th>
                                <th>分组名称</th>
                                <th>登录次数</th>
                                <th>登录时间</th>
                                <th>姓名</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="show">
                                <!-- tp用volist俩循环输出从数据库读出的内容 -->
                                <?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vs): $mod = ($i % 2 );++$i;?><tr>
                                        <td><?php echo ($vs["id"]); ?></td>
                                        <td><?php echo ($vs["name"]); ?></td>
                                        <td>
                                            <?php if($vs['img'] == ''): ?><img src="/Public/Admin/img/1.png">
                                                <?php else: ?>
                                                <img src="/<?php echo ($vs["img"]); ?>"><?php endif; ?>
                                        </td>
                                        <td><?php echo ($vs["title"]); ?></td>
                                        <td><?php echo ($vs["loginnum"]); ?></td>
                                        <td><?php echo ($vs["logintime"]); ?></td>
                                        <td><?php echo ($vs["realname"]); ?></td>
                                        <td>
                                            <?php if(($vs["status"] == 1)): ?><a href="javascript:Alterstate(<?php echo ($vs["id"]); ?>)" id="state<?php echo ($vs["id"]); ?>" class="label label-primary">正常</a>
                                            <?php else: ?>
                                                <a href="javascript:Alterstate(<?php echo ($vs["id"]); ?>)" id="state<?php echo ($vs["id"]); ?>" class="label label-danger">禁用</a><?php endif; ?>
                                        </td>
                                        <td>
                                            <a href="<?php echo U('User/edit?id='.$vs['id']);?>" class="label label-primary"><i class="fa fa-edit"></i> 修改</a>
                                            &nbsp;&nbsp;&nbsp;&nbsp;
                                            <a href="javascript:del(<?php echo ($vs["id"]); ?>);" class="label label-danger"><i class="fa fa-trash"></i> 删除</a>
                                        </td>
                                    </tr><?php endforeach; endif; else: echo "" ;endif; ?>
                                </tbody>
                        	</table>                        
                        	<div id="pages" class="page" style="text-align: center"></div>
                    </div>
                 
                </div>
            </div>
        </div>

    </div>
</div>
<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/layer/layer.js"></script>
<script src="/Public/Admin/js/plugins/layer/laypage/laypage.js"></script>
<script src="/Public/Admin/js/comment.js"></script>
<script>
    //修改状态
    function Alterstate(id){
        var objectState = $('#state'+id);
        /*通过ajax post方法将后台从数据库内查询的情况返回给前台回调函数data代表一个数组通过来判断data.status来判断当前的操作能否成功
        成功后在判断数据中的status的是否正常或者禁用
        */
        comment.status("<?php echo U('User/Alterstate');?>",id,objectState);
    }
    //删除是通过id来操作的
    function del(id){
        comment.del("<?php echo U('User/del');?>",id,"<?php echo U('User/index');?>");  
    }
    //第三种js写法laypage插件引入css 和 js
    var title = '<?php echo ($title); ?>';
    laypage({
          cont:'pages',//容器就是div定义的id
          pages: <?php echo ($countnum); ?>, //可以叫服务端把总页数放在某一个隐藏域，再获取， 从后台获取的总页码数
          skin: '#009688',
          skip: true, //是否开启跳页
          curr: function(){ //通过url获取当前页，也可以同上（pages）方式获取
            var page = location.search.match(/page=(\d+)/);//获取当前页（地址栏中获取的有参数page）到后台的$page
            return page ? page[1] : 1;
          }(), 
          //点击跳转时出发回调函数first是形参不是第一页的话就是跳转到点击的页面
          jump: function(e, first){ //触发分页后的回调
            if(!first){ //一定要加此判断，否则初始时会无限刷新
              location.href = '?title='+ title +'&page='+e.curr;//e是返回的很多参数只选取当前页的参数
            }
          }
    });
    // var page = 1,title = '';//声明title默认清空为空
    // function demo(curr,title = ''){
    //       $.getJSON("<?php echo U('User/listpage');?>",{page: curr || 1},function(res){
    //         //此处仅仅是为了演示变化的内容
    //         var demoContent = (new Date().getTime()/Math.random()/1000)|0;
    //         document.getElementById('show').innerHTML = res.content + demoContent;//返回展示通过js来实现控制页面分页
    //         //显示分页
    //         laypage({
    //           cont: 'pages', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
    //           pages: res.pagenum, //通过后台拿到的总页数
    //           curr: curr || 1, //当前页
    //           jump: function(obj, first){ //触发分页后的回调
    //             if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
    //               demo(obj.curr);
    //             }
    //           }
    //         });
    //     });
    // }
    // demo();
    // $('#submit').click(function(){
    //     title = $('#title').val();
    //     if(title == ''){
    //         comment.error('搜索内容不能为空！');
    //         return false;
    //     }
    //     demo(page,title);//调用函数
    // });

</script>
</body>
</html>